package com.minimalist.lindi.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.minimalist.common.entity.lindi.po.LindiPurchaseApplicationProjectItem;
import com.minimalist.common.entity.lindi.vo.purchaseapplicationprojectitem.LindiPurchaseApplicationProjectItemVO;
import com.minimalist.lindi.mapper.LindiPurchaseApplicationProjectItemMapper;
import com.minimalist.lindi.service.LindiPurchaseApplicationProjectItemService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.minimalist.common.entity.lindi.po.table.LindiPurchaseApplicationProjectItemTableDef.LINDI_PURCHASE_APPLICATION_PROJECT_ITEM;

/**
 * 林地指标交易平台_购买申请项目表 服务层实现。
 *
 * @author 11987
 * @since 2025-07-01
 */
@Service
public class LindiPurchaseApplicationProjectItemServiceImpl extends ServiceImpl<LindiPurchaseApplicationProjectItemMapper, LindiPurchaseApplicationProjectItem> implements LindiPurchaseApplicationProjectItemService{

    @Override
    public List<LindiPurchaseApplicationProjectItemVO> getProjectItemListByPurchaseApplicationId(Long purchaseApplicationId) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(LINDI_PURCHASE_APPLICATION_PROJECT_ITEM.PURCHASE_APPLICATION_ID.eq(purchaseApplicationId));
        List<LindiPurchaseApplicationProjectItem> projectItemList = list(queryWrapper);
        return BeanUtil.copyToList(projectItemList, LindiPurchaseApplicationProjectItemVO.class);
    }

    @Override
    public void batchAddProjectItems(List<LindiPurchaseApplicationProjectItemVO> projectItemList) {
        if (projectItemList != null && !projectItemList.isEmpty()) {
            List<LindiPurchaseApplicationProjectItem> poList = BeanUtil.copyToList(projectItemList, LindiPurchaseApplicationProjectItem.class);
            saveBatch(poList);
        }
    }

    @Override
    public void deleteProjectItemsByPurchaseApplicationId(Long purchaseApplicationId) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(LINDI_PURCHASE_APPLICATION_PROJECT_ITEM.PURCHASE_APPLICATION_ID.eq(purchaseApplicationId));
        remove(queryWrapper);
    }
}
